import {Texture} from './Texture';
import { Engine } from '../Engine';
class Texture2DArray extends Texture{
    constructor(opts){
        super(opts)
    }
    get dimension() {
        return this._dimension;
    }
    set dimension(v) {
        this._dimension = '2d';
    }
    get viewDimension() {
        return this._viewDimension;
    }
    set viewDimension(v) {
        this._viewDimension = '2d-array';
    }
    toGPU() {
        if(!this.image) {
            return
        }
        let data = this.image;
        const texture = Engine.instance.device.createTexture({
            dimension: this.dimension,
            size: [data[0].width, data[0].height, 6],
            format: this.format,
            usage:this.usage
        });
  
        for (let i = 0; i < data.length; i++) {
            const imageBitmap = data[i];
            Engine.instance.device.queue.copyExternalImageToTexture(
                { source: imageBitmap },
                { texture: texture, origin: [0, 0, i] },
                [imageBitmap.width, imageBitmap.height]
            );
        }
        this.image=null
        let {  dimension, viewDimension, format, usage, sampler, uvIndex, uvTransform } = this;
        return {
            dimension,
            viewDimension,
            format,
            usage,
            sampler,
            multisampled,
            sampleType,
            uvIndex,
            uvTransform,
            texture: texture
        }
    }
}
export {Texture2DArray}